package com.lc.guessTheWords.core;

import android.app.Activity;
import android.content.SharedPreferences;

import com.lc.guessTheWords.R;
import com.lc.guessTheWords.util.ADHelper;
import com.wiyun.engine.nodes.CharMap;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.types.WYRect;

public class GameSystem {
	public static Activity AndroidContext;
	public static SharedPreferences SharedSettings;
	/**
	 * 屏幕宽度
	 */
	public static int Screen_Width = 480;

	/**
	 * 屏幕高度
	 */
	public static int Screen_Height = 800;

	/**
	 * 游戏行数
	 */
	public static int GameRows = 10;

	/**
	 * 游戏列数
	 */
	public static int GameColumns = 10;

	/**
	 * 游戏两边留空
	 */
	public static final int Margin_Side = 20;

	public static int GameMatrixStartY = 675;

	/**
	 * 字符框大小
	 */
	public static final float CharSize = 44;

	/**
	 * 字符框中的字符大小
	 */
	public static final int CharBlockFontSize = 30;

	// 按钮高度宽度
	public static final float KeyHeight = 51;
	public static final float KeyWidth = 60;

	// Tip
	public static final int TipFontSize = 24;

	// stage 相关
	public static final int stageCount = 180;

	public static void loadAllResource() {
		loadTexture();
		loadCharMap();
		loadSound();
		initSetting();
		ADHelper.initAD();
	}

	private static void loadSound() {
		// AudioManager.preloadBackgroundMusic(R.raw.background);
		// AudioManager.preloadEffect(R.raw.clear);
		// AudioManager.preloadEffect(R.raw.click);
		// AudioManager.preloadEffect(R.raw.lose);
		// AudioManager.preloadEffect(R.raw.readygo);
		// AudioManager.preloadEffect(R.raw.win);
		// AudioManager.preloadEffect(R.raw.click);
		// AudioManager.preloadEffect(R.raw.buy);
	}

	public static CharMap charMap;

	private static void loadCharMap() {
		charMap = CharMap.make();
		for (int i = 0; i < 10; i++) {
			charMap.mapChar(WYRect.make(i * 30, 0, 30, 40),
					(i + "").toCharArray()[0]);
		}
	}

	public static Texture2D tex_char_background;
	public static Texture2D tex_game_background;
	public static Texture2D tex_main_background;
	public static Texture2D tex_title_feng;
	public static Texture2D tex_title_kuang;
	public static Texture2D tex_title_tian;
	public static Texture2D tex_title_zi;
	public static Texture2D tex_stage_block;
	public static Texture2D tex_stage_block_locked;
	public static Texture2D tex_numbers_48;
	public static Texture2D tex_star_full;
	public static Texture2D tex_star_empty;
	public static Texture2D tex_shop_background;
	public static Texture2D tex_chars_back;
	public static Texture2D tex_pause_back;
	public static Texture2D tex_gamebuttom_back;

	private static void loadTexture() {

		tex_char_background = Texture2D.makePNG(R.drawable.char_background);
		tex_game_background = Texture2D.makeJPG(R.drawable.gamebackground);
		tex_main_background = Texture2D.makeJPG(R.drawable.main_background);
		tex_title_feng = Texture2D.makePNG(R.drawable.title_feng);
		tex_title_kuang = Texture2D.makePNG(R.drawable.title_kuang);
		tex_title_tian = Texture2D.makePNG(R.drawable.title_tian);
		tex_title_zi = Texture2D.makePNG(R.drawable.title_zi);
		tex_stage_block = Texture2D.makePNG(R.drawable.stage_block);
		tex_stage_block_locked = Texture2D
				.makePNG(R.drawable.stage_block_locked);
		tex_numbers_48 = Texture2D.makePNG(R.drawable.numbers_48);
		tex_star_full = Texture2D.makePNG(R.drawable.star_full);
		tex_star_empty = Texture2D.makePNG(R.drawable.star_empty);
		tex_shop_background = Texture2D.makePNG(R.drawable.shopbackground);
		tex_chars_back = Texture2D.makePNG(R.drawable.chars_back);
		tex_pause_back = Texture2D.makePNG(R.drawable.pause_background);
		tex_gamebuttom_back = Texture2D.makePNG(R.drawable.game_button_back);

		tex_gamebuttom_back.loadTexture();
		tex_pause_back.loadTexture();
		tex_chars_back.loadTexture();
		tex_shop_background.loadTexture();
		tex_star_full.loadTexture();
		tex_star_empty.loadTexture();
		tex_stage_block.loadTexture();
		tex_stage_block_locked.loadTexture();
		tex_main_background.loadTexture();
		tex_char_background.loadTexture();
		tex_game_background.loadTexture();
		tex_title_feng.loadTexture();
		tex_title_kuang.loadTexture();
		tex_title_tian.loadTexture();
		tex_title_zi.loadTexture();
	}

	private static void initSetting() {
		SharedSettings = AndroidContext.getPreferences(Activity.MODE_PRIVATE);
		StageManager.instance.initStageData();
	}
}
